pp108 : Calling a Web Service from a WS-AppServer Application

Calling a Web Service from a WS-AppServer Application

This topic describes the procedure to call a Web service from a WS-AppServer application.

While building a WS-AppServer application, you may feel the need to implement additional business logic that resides in a separate Web service. To fulfil this requirement, you need a provision within WS-AppServer application to call that Web service.

The Extension class in WS-AppServer provides this flexibility, where you can add the required code to call the Web service. During runtime, the application logic will call the Web service and execute the desired functionality.

  1. Identify the Web service that you want to integrate in your application logic.
  2. In the Extension class that contains the custom logic, add the code that calls the external Web service during runtime (see code snippet in following example).
  3. Regenerate the Java code and the Web service Interface.

The application is equipped with the necessary logic to call a Web service.

Example

Assume that you are an automobile dealer dealing with various automobile manufacturers. You want to procure spare parts for a particular make and model. The information pertaining to a specific spare part resides with the automobile manufacturer.

Through your WS-AppServer application, you want to call the Web service (published by that manufacturer) that contains information on the spare part. To enable this, write a method in your application to send a SOAP request to the Web service with specific parameters, and get the spare part details in the response. Based on the results, you can program further action.

The following sample code illustrates how to call such a Web service:

 int sparePartNumber = 110; //request parameter value String[] paramNames = { "PartNo" }; Object[] paramValues = { sparePartNumber }; //Construct a SOAPRequestObject that calls Process Platform web services SOAPRequestObject sro = new SOAPRequestObject( "http://schemas.cordys.com/automotive", "GetSparesObject", paramNames, paramValues); //Execute the soap request. This is a synchronous call. int response = sro.execute(); //the above method call will be transformed into below soap call /* <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Body> <GetSparesObject xmlns="http://schemas.cordys.com/automotive"> <PartNo>110</PartNo> </GetSparesObject> </SOAP:Body> </SOAP:Envelope> */ 

In the above code, GetSparesObject is the method, and 110 is the parameter value referring to the spare part number. At run time, the code constructs a new SOAP request, interacts with the Web service, and gets the required information in a response.